---
title: "Unit 2 homework instructions"
author: "Anonymous"
date: "4/1/2026"
output:
  html_document:
    toc: true
subtitle: DKU Stats 101 Spring 2026 Session 4
format: 
  html:
    embed-resources: true
---

```{r}
#| label: setup
#| include: false

# Put any setup code here
```

![](diabetes.jpeg)

## Scoring guide 

### Content

- The information requested in the question prompts are only a starting point, if you find other interesting information along the way, please report that. You don't need to look at the data forever but if there is obviously something else interesting in the data you should report it.
- You must have up to Question 2 completed for the homework check on April 5th
- You do not need to be an expert on diabetes for a good score, but I will expect you to look up basic information, such as "what is the meaning of inpatient?" and so on to help you understand and set expectations your data.
- The information requested in the question prompts are only a starting point, if you find other interesting information along the way, please report that. You don't need to look at the data forever but if there is obviously something else interesting in the data you should report it.

### Technical

- Make sure your graphs are produced using `ggplot()`, are well labeled, and are easy to read. 
- Make sure your tables are produced with the `kable()` function from the `knitr` package, are well labeled, and are easy to read. You can make your tables prettier with the `kableExtra` package.
- Make sure you do not have anything rendered in your HTML file besides your results and, when asked for by a question, your code. That means no warnings, messages, or other output should appear in your final rendered HTML file.
- Make sure to accurately  mark each page a question answer appears on when submitting on GradeScope. 

# Diabetes

One of the major health care costs is the length of time diabetes patients spend in a hospital each year and how many procedures they need when they are in the hospital. You will explore what variables are related to these problems in the following questions.

## Introduction

## Question 1: Describing your data (10 points)

### 1a. Where is this data from?

For this dataset, describe the data according to the five Ws & *how* defined in the textbook Chapter 1.2. What are some possible problems with the *who* and *what* of the dataset?

The dataset you are using for this assignment is a subset of the original dataset that can be found [here](https://archive.ics.uci.edu/dataset/296/diabetes+130-us+hospitals+for+years+1999-2008).

### 1b. What are the variable types?

For the following variables, please make a table. 

One column should be the variable name, the second should be the variable type as defined in the textbook Chapter 1.3, and the third the units of the variable (if applicable). 

- `patient_nbr`
- `race`
- `gender`
- `age_group`
- `age`
- `num_lab_procedures`
- `time_in_hospital`
- `number_diagnoses`

## Question 2: Association (20 points)


### 2a. Investigating `age_group` vs. `time_in_hospital`

Using the Think-Show-Tell framework from the textbook (example on page 213), please examine the relationship *in association [i.e. correlation] terms* between `age_group` and `time_in_hospital`. How strongly are they associated?

Note: for this question and all other Think sections in the homework, you do not need to report the W's of the data (you have already completed this in Q1)

> Think

*For this section, please write down your expectations, why you expect it, the variable meaning, and, given the variable type, the best way to display the data*

> Show

*For this section, please make an appropriate graph or table and briefly describe what you observe*

> Tell

*Please interpret the meaning of your finding here, especially with respect to your expectation*

### 2b. Investigating `age_group` vs. `num_procedures`

Using the Think-Show-Tell framework from the textbook, please examine the relationship *in association terms* between `age` and `rating_number`. How strongly are they associated? 

> Think

*For this section, please write down your expectations, why you expect it, the variable meaning, and, given the variable type, the best way to display the data*

> Show

*For this section, please make an appropriate graph or table and briefly describe what you observe*

> Tell

*Please interpret the meaning of your finding here, especially with respect to your expectation*

### 2c. Thinking about your results

Consider the results of 2a. and 2b. together. What can we understand about how books are rated on Amazon from this information? What do you think explains the relationships you have identified?

> **Complete up to here for Homework Check** - due April 5th at 11:59 pm.

## Question 3: Simple regression (20 points)

### 3a. Investigating `wgt_gropu` vs. `time_in_hospital`

Using the Think-Show-Tell framework from the textbook, please examine how the price of a book is related to the rating of a book.

> Think 

> Show 

> Tell

### 3b. Checking model fit

Make use of all the tools described in the textbook to assess model fit in the `Think again` section - if it is necessary to revise your model, do it in the `Think again` section. Then state any updated conclusions in the `Revising conclusions` section.

> Think again

> Revising conclusions

### 3c. Investigating `wgt_group` vs. `num_procedures`

Similar to 3a. and 3b., fully analyze the relationship between price and the weight of the book. 

> Think 

> Show 

> Tell

> Think again

> Revising conclusions

### 3d. Thinking about your results

What can we learn about how price is determined in these two investigations? Do the results surprise you? What lurking variables do you think could be at work here, if any?

## Question 4: Multiple regression (30 points)

### 4a. Investigating `time_in_hospital` vs. `age_group` and `wgt_group`

Using the Think-Show-Tell framework from the textbook, please examine, using a multiple regression model, how `time_in_hospital` relate to `age_group` and `wgt_group`. In the first Think-Show-Tell section, create the model with the specified, untransformed variables, checking the regression conditions but do not assess model fit. For the `Think again` section, assess model fit using all of the tools described in the textbook and revise your model, if necessary. 

> Think 

> Show 

> Tell

> Think again

> Revising conclusions

### 4b. Interpreting coefficients of 4a. model

Carefully interpret your coefficients from 4a. What do they mean? Are there any lurking variables here? How do these results differ from the results you found in Q2 and Q3?

> Think 

> Show 

> Tell

### 4c. Add the variables `race`, and `gender`

Now add the variables `race` and `gender` to your model and analyze the relationship similar to what you did in 4a. 

> Think 

> Show 

> Tell

> Think again

### 4d. Reinterpret your coefficients

Carefully re-interpret your coefficients from 4c and compare them to 4b. What do they mean? Any new lurking variables to consider?

> Think 

> Show 

> Tell

### 4e. Thinking about your results

Consider the results of 4a.-4d. together. What can we learn about what determines the length of hospital stay? How did your conclusions change from 2c. and 3d.? Why do you think they changed?

## Question 5: Your own investigation (20 points)

### 5a. Selecting your own question

Develop your own model of `num_procedures`. Use the Think-Show-Tell procedure to conduct your investigation. Think deeply about what your result means and interpret your coefficients carefully. 

> Think 

> Show 

> Tell

> Think again

### 5b. In summary

Sum up everything that you have learned from questions 1-5. Do not simply repeat/rephrase your previous results but try to say something larger that synthesizes the results together to draw a more meaningful general conclusion.